<template>
  <div class="weather-app">
    <!-- 加载状态 -->
    <div v-if="loading" class="loading-container">
      <div class="loading-spinner"></div>
      <p>正在获取天气数据...</p>
    </div>

    <!-- 错误状态 -->
    <div v-else-if="error" class="error-container">
      <div class="error-icon">⚠️</div>
      <p>{{ error }}</p>
      <button @click="refreshWeather" class="retry-button">重试</button>
    </div>

    <!-- 主内容区 -->
    <div v-else class="weather-main">
      <!-- 刷新按钮和更新时间 -->
      <div class="weather-header">
        <div class="update-time" v-if="lastUpdateTime">
          更新于 {{ lastUpdateTime }}
        </div>
        <button @click="refreshWeather" class="refresh-button" title="刷新天气">
          🔄
        </button>
      </div>

      <!-- 当前天气 -->
      <div class="current-weather">
        <div class="location-info">
          <div class="location-icon">📍</div>
          <h1 class="location-name">{{ currentLocation }}</h1>
        </div>

        <div class="current-temp-container">
          <div class="weather-icon-large">{{ getCurrentWeatherIcon() }}</div>
          <div class="temperature-display">
            <span class="temp-value">{{ currentWeather.temp }}</span>
            <span class="temp-unit">°</span>
          </div>
        </div>

        <div class="weather-description">
          <h2 class="condition">{{ currentWeather.condition }}</h2>
          <div class="temp-range">
            <span class="high">最高 {{ currentWeather.high }}°</span>
            <span class="separator">•</span>
            <span class="low">最低 {{ currentWeather.low }}°</span>
          </div>
        </div>
      </div>

      <!-- 每小时预报 -->
      <div class="hourly-forecast section">
        <div class="section-header">
          <span class="header-icon">🕐</span>
          <h3>每小时预报</h3>
        </div>
        <div class="hourly-scroll">
          <div
            v-for="hour in hourlyForecast"
            :key="hour.time"
            class="hourly-item"
          >
            <div class="hour-time">{{ hour.time }}</div>
            <div class="hour-icon">{{ hour.icon }}</div>
            <div class="hour-temp">{{ hour.temp }}°</div>
          </div>
        </div>
      </div>

      <!-- 10天预报 -->
      <div class="daily-forecast section">
        <div class="section-header">
          <span class="header-icon">📅</span>
          <h3>10天预报</h3>
        </div>
        <div class="daily-list">
          <div
            v-for="day in dailyForecast"
            :key="day.day"
            class="daily-item"
          >
            <div class="day-name">{{ day.day }}</div>
            <div class="day-icon">{{ day.icon }}</div>
            <div class="day-temp-bar">
              <div class="temp-bar-container">
                <span class="temp-low">{{ day.low }}°</span>
                <div class="temp-bar-wrapper">
                  <div
                    class="temp-bar"
                    :style="getTempBarStyle(day.low, day.high)"
                  ></div>
                </div>
                <span class="temp-high">{{ day.high }}°</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 天气详情 -->
      <div class="weather-details">
        <div class="detail-grid">
          <!-- 体感温度 -->
          <div class="detail-card">
            <div class="detail-header">
              <span class="detail-icon">🌡️</span>
              <span class="detail-title">体感温度</span>
            </div>
            <div class="detail-value">{{ weatherDetails.feelsLike }}°</div>
            <div class="detail-description">与实际温度相似</div>
          </div>

          <!-- 紫外线指数 -->
          <div class="detail-card">
            <div class="detail-header">
              <span class="detail-icon">☀️</span>
              <span class="detail-title">紫外线指数</span>
            </div>
            <div class="detail-value">{{ weatherDetails.uvIndex }}</div>
            <div class="detail-description">{{ weatherDetails.uvLevel }}</div>
            <div class="detail-chart">
              <div class="uv-bar">
                <div
                  class="uv-fill"
                  :style="{ width: `${(weatherDetails.uvIndex / 11) * 100}%` }"
                ></div>
              </div>
            </div>
          </div>

          <!-- 日出日落 -->
          <div class="detail-card">
            <div class="detail-header">
              <span class="detail-icon">🌅</span>
              <span class="detail-title">日出日落</span>
            </div>
            <div class="sun-times">
              <div class="sun-time">
                <span class="sun-label">日出</span>
                <span class="sun-value">{{ weatherDetails.sunrise }}</span>
              </div>
              <div class="sun-arc">
                <svg viewBox="0 0 100 50" class="arc-svg">
                  <path
                    d="M 10 45 Q 50 5, 90 45"
                    fill="none"
                    stroke="rgba(255, 204, 0, 0.3)"
                    stroke-width="2"
                  />
                  <circle cx="50" cy="25" r="4" fill="#FFCC00" />
                </svg>
              </div>
              <div class="sun-time">
                <span class="sun-label">日落</span>
                <span class="sun-value">{{ weatherDetails.sunset }}</span>
              </div>
            </div>
          </div>

          <!-- 降水量 -->
          <div class="detail-card">
            <div class="detail-header">
              <span class="detail-icon">💧</span>
              <span class="detail-title">降水量</span>
            </div>
            <div class="detail-value">{{ weatherDetails.precipitation || 0 }} mm</div>
            <div class="detail-description">过去24小时</div>
          </div>

          <!-- 风速 -->
          <div class="detail-card">
            <div class="detail-header">
              <span class="detail-icon">💨</span>
              <span class="detail-title">风速</span>
            </div>
            <div class="detail-value">{{ weatherDetails.wind }} km/h</div>
            <div class="detail-description">{{ weatherDetails.windDirection }}</div>
            <div class="wind-compass">
              <div class="compass-circle">
                <div
                  class="compass-arrow"
                  :style="{ transform: `rotate(${weatherDetails.windDegree}deg)` }"
                >↑</div>
              </div>
            </div>
          </div>

          <!-- 湿度 -->
          <div class="detail-card">
            <div class="detail-header">
              <span class="detail-icon">💦</span>
              <span class="detail-title">湿度</span>
            </div>
            <div class="detail-value">{{ weatherDetails.humidity }}%</div>
            <div class="detail-description">露点 {{ weatherDetails.dewPoint }}°</div>
            <div class="humidity-bar">
              <div
                class="humidity-fill"
                :style="{ width: `${weatherDetails.humidity}%` }"
              ></div>
            </div>
          </div>

          <!-- 能见度 -->
          <div class="detail-card">
            <div class="detail-header">
              <span class="detail-icon">👁️</span>
              <span class="detail-title">能见度</span>
            </div>
            <div class="detail-value">{{ weatherDetails.visibility }} km</div>
            <div class="detail-description">{{ weatherDetails.visibilityDesc }}</div>
          </div>

          <!-- 气压 -->
          <div class="detail-card">
            <div class="detail-header">
              <span class="detail-icon">📊</span>
              <span class="detail-title">气压</span>
            </div>
            <div class="detail-value">{{ weatherDetails.pressure }} hPa</div>
            <div class="detail-description">{{ weatherDetails.pressureTrend }}</div>
          </div>

          <!-- 空气质量 -->
          <div class="detail-card air-quality">
            <div class="detail-header">
              <span class="detail-icon">🍃</span>
              <span class="detail-title">空气质量</span>
            </div>
            <div class="detail-value">{{ weatherDetails.aqi || '无' }}</div>
            <div class="detail-description aqi-level" :class="getAqiClass()">
              {{ weatherDetails.aqiLevel }}
            </div>
            <div class="aqi-bar" v-if="weatherDetails.aqi > 0">
              <div class="aqi-gradient"></div>
              <div
                class="aqi-indicator"
                :style="{ left: `${(weatherDetails.aqi / 200) * 100}%` }"
              ></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, computed, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useWeatherStore } from '@/stores/weather.ts'
import { useDesktopStore } from '@/stores/desktop.ts'

// 使用stores
const weatherStore = useWeatherStore()
const desktopStore = useDesktopStore()

// 从weather store中获取天气数据
const { currentWeather, hourlyForecast, dailyForecast, weatherDetails, lastUpdateTime } = storeToRefs(weatherStore)

// 从desktop store中获取用户地区信息
const userLocation = computed(() => desktopStore.userAccount.location)

// 计算当前位置显示
const currentLocation = computed(() => `${userLocation.value.city} ${userLocation.value.county}`)

// 从用户设置获取省市县信息
const province = computed(() => userLocation.value.province)
const city = computed(() => userLocation.value.city)
const county = computed(() => userLocation.value.county)

// 加载和错误状态（本地状态，不需要持久化）
const loading = ref(true)
const error = ref('')

// 监听用户地区变化，自动刷新天气
watch(userLocation, (newLocation, oldLocation) => {
  // 只在地区实际变化时刷新（避免初始化时重复请求）
  if (oldLocation && (
    newLocation.province !== oldLocation.province ||
    newLocation.city !== oldLocation.city ||
    newLocation.county !== oldLocation.county
  )) {
    // 同步更新weather store的location
    weatherStore.setLocation(newLocation)
    // 刷新天气数据
    fetchWeatherData()
  }
}, { deep: true })

// 天气代码转换为emoji图标
function getWeatherIcon(weatherCode: string, isNight = false): string {
  const iconMap: Record<string, { day: string; night: string }> = {
    '00': { day: '☀️', night: '🌙' }, // 晴
    '01': { day: '🌤️', night: '🌙' }, // 多云
    '02': { day: '⛅', night: '☁️' }, // 少云/阴
    '03': { day: '🌦️', night: '🌦️' }, // 阵雨
    '04': { day: '🌫️', night: '🌫️' }, // 雾
    '05': { day: '🌫️', night: '🌫️' }, // 霾
    '06': { day: '🌧️', night: '🌧️' }, // 雨
    '07': { day: '🌧️', night: '🌧️' }, // 小雨
    '08': { day: '🌧️', night: '🌧️' }, // 中雨
    '09': { day: '⛈️', night: '⛈️' }, // 大雨
    '10': { day: '⛈️', night: '⛈️' }, // 暴雨
    '11': { day: '⛈️', night: '⛈️' }, // 大暴雨
    '12': { day: '⛈️', night: '⛈️' }, // 特大暴雨
    '13': { day: '🌨️', night: '🌨️' }, // 阵雪
    '14': { day: '❄️', night: '❄️' }, // 小雪
    '15': { day: '❄️', night: '❄️' }, // 中雪
    '16': { day: '❄️', night: '❄️' }, // 大雪
    '17': { day: '❄️', night: '❄️' }, // 暴雪
    '18': { day: '🌦️', night: '🌦️' }, // 雨夹雪
    '19': { day: '⛈️', night: '⛈️' }, // 雷阵雨
    '20': { day: '⛈️', night: '⛈️' }, // 雷阵雨伴有冰雹
    '53': { day: '💨', night: '💨' }, // 浮尘
    '54': { day: '💨', night: '💨' }, // 扬沙
    '55': { day: '🌪️', night: '🌪️' }, // 沙尘暴
  }
  const icon = iconMap[weatherCode] || { day: '⛅', night: '🌙' }
  return isNight ? icon.night : icon.day
}

// 风向角度映射
function getWindDegree(windDirection: string): number {
  const directionMap: Record<string, number> = {
    '0': 0,   // 无持续风向
    '1': 45,  // 东北风
    '2': 90,  // 东风
    '3': 135, // 东南风
    '4': 180, // 南风
    '5': 225, // 西南风
    '6': 270, // 西风
    '7': 315, // 西北风
    '8': 0,   // 北风
    '9': 999, // 旋转风
  }
  return directionMap[windDirection] || 0
}

// 解析紫外线级别
function parseUVLevel(level: string): { index: number; level: string } {
  const uvMap: Record<string, number> = {
    '最弱': 1,
    '弱': 3,
    '中等': 5,
    '强': 7,
    '很强': 9,
    '极强': 11
  }
  return {
    index: uvMap[level] || 5,
    level: level
  }
}

// 解析真实的每小时预报数据
function parseHourlyForecastData(forecast1h: any) {
  const forecast = []
  const currentHour = new Date().getHours()

  // 取前12小时的数据
  for (let i = 0; i < Math.min(12, Object.keys(forecast1h).length); i++) {
    const hourData = forecast1h[i.toString()]
    if (!hourData) continue

    const updateTime = hourData.update_time
    const hour = parseInt(updateTime.substring(8, 10))
    const isNight = hour < 6 || hour >= 18

    forecast.push({
      time: i === 0 ? '现在' : `${hour.toString().padStart(2, '0')}:00`,
      icon: getWeatherIcon(hourData.weather_code, isNight),
      temp: parseInt(hourData.degree)
    })
  }

  return forecast
}

// 解析真实的未来天气预报数据
function parseDailyForecastData(forecast24h: any) {
  const forecast = []
  const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']

  // 遍历所有预报数据（通常是7-8天）
  const keys = Object.keys(forecast24h).sort()
  for (const key of keys) {
    const dayData = forecast24h[key]
    if (!dayData) continue

    // 解析日期
    const dateStr = dayData.time // 格式: 2025-10-23
    const date = new Date(dateStr)
    const today = new Date()
    today.setHours(0, 0, 0, 0)
    date.setHours(0, 0, 0, 0)

    let dayName = ''
    const diffDays = Math.floor((date.getTime() - today.getTime()) / (1000 * 60 * 60 * 24))

    if (diffDays === 0) {
      dayName = '今天'
    } else if (diffDays === 1) {
      dayName = '明天'
    } else {
      dayName = weekDays[date.getDay()]
    }

    // 使用白天的天气
    forecast.push({
      day: dayName,
      icon: getWeatherIcon(dayData.day_weather_code, false),
      high: parseInt(dayData.max_degree),
      low: parseInt(dayData.min_degree)
    })
  }

  return forecast
}

const baseURL = "https://sakura.faruzan.com/v1";

// 获取天气数据
async function fetchWeatherData() {
  try {
    loading.value = true
    error.value = ''

    const weatherTypes = 'observe|forecast_1h|forecast_24h|index|alarm|limit|tips|rise'
    const url = `${baseURL}/weather/common?source=pc&weather_type=${weatherTypes}&province=${province.value}&city=${city.value}&county=${county.value}`

    const response = await fetch(url)
    const data = await response.json()

    if (data.code === 0 && data.msg?.data?.observe) {
      const apiData = data.msg.data
      const observe = apiData.observe

      // 获取今日的最高最低温度
      const todayForecast = apiData.forecast_24h?.['1']
      const maxTemp = todayForecast ? parseInt(todayForecast.max_degree) : parseInt(observe.degree) + 5
      const minTemp = todayForecast ? parseInt(todayForecast.min_degree) : parseInt(observe.degree) - 3

      // 获取日出日落数据
      const todayRise = apiData.rise?.['0']
      const sunrise = todayRise?.sunrise || '06:30'
      const sunset = todayRise?.sunset || '18:30'

      // 获取紫外线数据
      const uvData = apiData.index?.ultraviolet
      const uvInfo = parseUVLevel(uvData?.info || '中等')

      // 获取AQI数据（从forecast_24h中获取）
      const aqiData = todayForecast ? {
        aqi: todayForecast.aqi,
        level: todayForecast.aqi_name
      } : { aqi: 0, level: '无' }

      const temp = parseInt(observe.degree)

      // 解析真实的每小时预报
      let parsedHourlyForecast
      if (apiData.forecast_1h) {
        parsedHourlyForecast = parseHourlyForecastData(apiData.forecast_1h)
      } else {
        parsedHourlyForecast = generateHourlyForecastData(temp, observe.weather_code)
      }

      // 解析真实的未来天气预报
      let parsedDailyForecast
      if (apiData.forecast_24h) {
        parsedDailyForecast = parseDailyForecastData(apiData.forecast_24h)
      } else {
        parsedDailyForecast = generateDailyForecastData(temp, observe.weather_code)
      }

      // 批量更新store中的所有数据
      weatherStore.updateAllWeatherData({
        currentWeather: {
          temp: temp,
          high: maxTemp,
          low: minTemp,
          condition: observe.weather,
          weatherCode: observe.weather_code
        },
        weatherDetails: {
          feelsLike: temp,
          uvIndex: uvInfo.index,
          uvLevel: uvData?.info || '无',
          sunrise: sunrise,
          sunset: sunset,
          precipitation: parseFloat(observe.precipitation) || 0,
          wind: parseFloat(observe.wind_power.split('-')[0]) * 5,
          windDirection: observe.wind_direction_name,
          windDegree: getWindDegree(observe.wind_direction),
          humidity: parseInt(observe.humidity),
          dewPoint: temp - Math.round((100 - parseInt(observe.humidity)) / 5),
          visibility: 10,
          visibilityDesc: '良好',
          pressure: parseInt(observe.pressure),
          pressureTrend: '稳定',
          aqi: aqiData.aqi,
          aqiLevel: aqiData.level
        },
        hourlyForecast: parsedHourlyForecast,
        dailyForecast: parsedDailyForecast,
        lastUpdateTime: formatUpdateTime(observe.update_time)
      })

    } else {
      throw new Error('获取天气数据失败')
    }
  } catch (err) {
    error.value = '无法获取天气数据，请稍后重试'
    console.error('Weather API Error:', err)
  } finally {
    loading.value = false
  }
}

// 格式化更新时间
function formatUpdateTime(updateTime: string): string {
  if (!updateTime || updateTime.length !== 12) return ''
  const year = updateTime.substring(0, 4)
  const month = updateTime.substring(4, 6)
  const day = updateTime.substring(6, 8)
  const hour = updateTime.substring(8, 10)
  const minute = updateTime.substring(10, 12)
  return `${month}-${day} ${hour}:${minute}`
}

// 生成每小时预报（模拟数据）
function generateHourlyForecastData(baseTemp: number, weatherCode: string) {
  const forecast = []
  const currentHour = new Date().getHours()

  for (let i = 0; i < 12; i++) {
    const hour = (currentHour + i) % 24
    const isNight = hour < 6 || hour >= 18
    const temp = baseTemp + Math.floor(Math.random() * 3) - 1

    forecast.push({
      time: i === 0 ? '现在' : `${hour.toString().padStart(2, '0')}:00`,
      icon: getWeatherIcon(weatherCode, isNight),
      temp: temp
    })
  }

  return forecast
}

// 生成10天预报（模拟数据）
function generateDailyForecastData(baseTemp: number, weatherCode: string) {
  const days = ['今天', '周一', '周二', '周三', '周四', '周五', '周六', '周日']
  const forecast = []

  for (let i = 0; i < 10; i++) {
    const dayIndex = new Date().getDay()
    const dayName = i === 0 ? '今天' : days[(dayIndex + i) % 7 === 0 ? 7 : (dayIndex + i) % 7]
    const variation = Math.floor(Math.random() * 5) - 2
    const high = baseTemp + 5 + variation
    const low = baseTemp - 3 + variation

    // 随机天气变化
    const randomCodes = ['00', '01', '02', '03', '07', '19']
    const randomCode = i === 0 ? weatherCode : randomCodes[Math.floor(Math.random() * randomCodes.length)]

    forecast.push({
      day: dayName,
      icon: getWeatherIcon(randomCode, false),
      high: high,
      low: low
    })
  }

  return forecast
}

// 刷新天气数据
function refreshWeather() {
  fetchWeatherData()
}

// 组件挂载时同步地区并获取数据
onMounted(() => {
  // 同步用户设置中的地区到weather store
  weatherStore.setLocation(userLocation.value)
  // 获取天气数据
  fetchWeatherData()
})

function getCurrentWeatherIcon() {
  const hour = new Date().getHours()
  const isNight = hour < 6 || hour >= 18
  return getWeatherIcon(currentWeather.value.weatherCode, isNight)
}

function getTempBarStyle(low: number, high: number) {
  const minTemp = 10
  const maxTemp = 30
  const range = maxTemp - minTemp

  const startPercent = ((low - minTemp) / range) * 100
  const widthPercent = ((high - low) / range) * 100

  return {
    left: `${startPercent}%`,
    width: `${widthPercent}%`
  }
}

function getAqiClass() {
  const aqi = weatherDetails.value.aqi
  if (aqi <= 50) return 'aqi-good'
  if (aqi <= 100) return 'aqi-moderate'
  if (aqi <= 150) return 'aqi-unhealthy-sensitive'
  return 'aqi-unhealthy'
}
</script>

<style scoped>
.weather-app {
  height: 100%;
  overflow-y: auto;
  background: linear-gradient(to bottom, #4A90E2 0%, #7CB9E8 50%, #B0D4F1 100%);
  color: white;
  position: relative;
}

/* 深色模式 */
html.dark-mode .weather-app {
  background: linear-gradient(to bottom, #1a2332 0%, #2a3a52 50%, #3a4a62 100%);
}

/* 加载状态 */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 20px;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-container p {
  font-size: 16px;
  opacity: 0.9;
  margin: 0;
}

/* 错误状态 */
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  padding: 32px;
  text-align: center;
}

.error-icon {
  font-size: 64px;
  opacity: 0.9;
}

.error-container p {
  font-size: 16px;
  opacity: 0.9;
  margin: 0;
}

.retry-button {
  background: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
}

.retry-button:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.retry-button:active {
  transform: translateY(0);
}

/* 天气头部 */
.weather-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  margin-bottom: 4px;
}

.update-time {
  font-size: 11px;
  opacity: 0.85;
  font-weight: 400;
}

.refresh-button {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
}

.refresh-button:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(180deg);
}

.refresh-button:active {
  transform: rotate(180deg) scale(0.95);
}

html.dark-mode .refresh-button {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

html.dark-mode .refresh-button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.weather-main {
  padding: 40px 20px 20px;
  max-width: 900px;
  margin: 0 auto;
}

/* 当前天气 */
.current-weather {
  text-align: center;
  margin-bottom: 24px;
  padding: 20px 0;
}

.location-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
}

.location-icon {
  font-size: 16px;
  opacity: 0.9;
}

.location-name {
  font-size: 22px;
  font-weight: 300;
  margin: 0;
  letter-spacing: 0.5px;
}

.current-temp-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 16px 0;
}

.weather-icon-large {
  font-size: 72px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

.temperature-display {
  display: flex;
  align-items: flex-start;
  line-height: 1;
}

.temp-value {
  font-size: 72px;
  font-weight: 200;
  letter-spacing: -3px;
}

.temp-unit {
  font-size: 36px;
  font-weight: 200;
  margin-top: 4px;
  opacity: 0.8;
}

.weather-description {
  margin-top: 12px;
}

.condition {
  font-size: 20px;
  font-weight: 400;
  margin: 0 0 8px 0;
  opacity: 0.95;
}

.temp-range {
  font-size: 15px;
  opacity: 0.85;
  font-weight: 300;
}

.separator {
  margin: 0 12px;
  opacity: 0.6;
}

/* 区块样式 */
.section {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

html.dark-mode .section {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  opacity: 0.9;
}

.header-icon {
  font-size: 14px;
}

.section-header h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
}

/* 每小时预报 */
.hourly-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 0;
  scrollbar-width: none;
}

/* 每小时预报滚动条隐藏 */
.hourly-scroll {
  scrollbar-width: none;
}

.hourly-scroll::-webkit-scrollbar {
  display: none;
}

.hourly-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 50px;
  padding: 8px;
  border-radius: 10px;
  transition: all 0.2s;
}

.hourly-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

html.dark-mode .hourly-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.hour-time {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.85;
}

.hour-icon {
  font-size: 24px;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.15));
}

.hour-temp {
  font-size: 14px;
  font-weight: 500;
}

/* 10天预报 */
.daily-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.daily-item {
  display: grid;
  grid-template-columns: 60px 40px 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 10px;
  transition: all 0.2s;
}

.daily-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

html.dark-mode .daily-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.day-name {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.9;
}

.day-icon {
  font-size: 22px;
  text-align: center;
}

.day-temp-bar {
  display: flex;
  align-items: center;
}

.temp-bar-container {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.temp-low,
.temp-high {
  font-size: 12px;
  font-weight: 500;
  min-width: 28px;
  text-align: center;
  opacity: 0.85;
}

.temp-bar-wrapper {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.temp-bar {
  position: absolute;
  height: 100%;
  background: linear-gradient(90deg, #FFB347, #FF6B6B);
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* 天气详情 */
.weather-details {
  margin-top: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.detail-card {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 12px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: all 0.3s;
}

.detail-card:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

html.dark-mode .detail-card {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
}

html.dark-mode .detail-card:hover {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  opacity: 0.85;
}

.detail-icon {
  font-size: 16px;
}

.detail-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.detail-value {
  font-size: 28px;
  font-weight: 300;
  margin-bottom: 6px;
  line-height: 1;
}

.detail-description {
  font-size: 12px;
  opacity: 0.8;
  font-weight: 400;
}

/* 紫外线指数 */
.detail-chart {
  margin-top: 8px;
}

.uv-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
}

.uv-fill {
  height: 100%;
  background: linear-gradient(90deg, #4CAF50, #FFC107, #FF5722);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* 日出日落 */
.sun-times {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.sun-time {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
}

.sun-label {
  opacity: 0.7;
  font-size: 9px;
}

.sun-value {
  font-weight: 600;
  font-size: 12px;
}

.sun-arc {
  flex: 1;
  height: 30px;
}

.arc-svg {
  width: 100%;
  height: 100%;
}

/* 风速罗盘 */
.wind-compass {
  margin-top: 8px;
  display: flex;
  justify-content: center;
}

.compass-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.compass-arrow {
  font-size: 20px;
  transition: transform 0.5s ease;
}

/* 湿度 */
.humidity-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.humidity-fill {
  height: 100%;
  background: linear-gradient(90deg, #64B5F6, #42A5F5);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* 空气质量 */
.air-quality .detail-value {
  font-size: 32px;
}

.aqi-level {
  font-weight: 600;
  font-size: 14px;
}

.aqi-level.aqi-good {
  color: #4CAF50;
}

.aqi-level.aqi-moderate {
  color: #FFC107;
}

.aqi-level.aqi-unhealthy-sensitive {
  color: #FF9800;
}

.aqi-level.aqi-unhealthy {
  color: #F44336;
}

.aqi-bar {
  position: relative;
  height: 6px;
  margin-top: 8px;
  border-radius: 3px;
  overflow: hidden;
}

.aqi-gradient {
  height: 100%;
  background: linear-gradient(90deg,
    #4CAF50 0%,
    #8BC34A 16.67%,
    #FFEB3B 33.33%,
    #FFC107 50%,
    #FF9800 66.67%,
    #FF5722 83.33%,
    #F44336 100%
  );
}

.aqi-indicator {
  position: absolute;
  top: -2px;
  width: 10px;
  height: 10px;
  background: white;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  transform: translateX(-50%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: left 0.5s ease;
}

/* 滚动条针对蓝色背景优化 - 更柔和的白色 */
.weather-app:hover::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 1px rgba(255, 255, 255, 0.15);
  opacity: 1;
}

.weather-app::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 2px rgba(255, 255, 255, 0.2);
}

.weather-app::-webkit-scrollbar-thumb:active {
  background-color: rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 3px rgba(255, 255, 255, 0.25);
}

/* 响应式 */
@media (max-width: 768px) {
  .weather-main {
    padding: 36px 12px 12px;
  }

  .weather-icon-large {
    font-size: 60px;
  }

  .temp-value {
    font-size: 60px;
  }

  .temp-unit {
    font-size: 30px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .daily-item {
    grid-template-columns: 50px 35px 1fr;
  }
}
</style>

